Skip to content

zend_compile: Bundle function type constants into an zend_function_type enum#21208

Open
TimWolla wants to merge 1 commit intophp:masterfrom
TimWolla:zend-function-type
Open

zend_compile: Bundle function type constants into an zend_function_type enum#21208
TimWolla wants to merge 1 commit intophp:masterfrom
TimWolla:zend-function-type

Conversation

@TimWolla
Copy link
Member

This clarifies the relationship between these constants and improves type safety a little.

Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable, thanks!

…ype` enum

This clarifies the relationship between these constants and improves type
safety a little.
Comment on lines +500 to +516
#if __STDC_VERSION__ >= 202311L || defined(__cplusplus)
enum zend_function_type: uint8_t
#else
enum zend_function_type
#endif
{
ZEND_INTERNAL_FUNCTION = 1,
ZEND_USER_FUNCTION = 2,
ZEND_EVAL_CODE = 4,
};

#if __STDC_VERSION__ >= 202311L || defined(__cplusplus)
typedef enum zend_function_type zend_function_type;
#else
typedef uint8_t zend_function_type;
#endif

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better indeed, but I'd make it even more "compact". My motivation for this is the reduced "human parsing effort" overhead wrt preprocessor instructions.

Suggested change
#if __STDC_VERSION__ >= 202311L || defined(__cplusplus)
enum zend_function_type: uint8_t
#else
enum zend_function_type
#endif
{
ZEND_INTERNAL_FUNCTION = 1,
ZEND_USER_FUNCTION = 2,
ZEND_EVAL_CODE = 4,
};
#if __STDC_VERSION__ >= 202311L || defined(__cplusplus)
typedef enum zend_function_type zend_function_type;
#else
typedef uint8_t zend_function_type;
#endif
#if __STDC_VERSION__ >= 202311L || defined(__cplusplus)
typedef enum zend_function_type zend_function_type;
enum zend_function_type: uint8_t
#else
typedef uint8_t zend_function_type;
enum zend_function_type
#endif
{
ZEND_INTERNAL_FUNCTION = 1,
ZEND_USER_FUNCTION = 2,
ZEND_EVAL_CODE = 4,
};

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially tried that, but it didn't work for the C23 compiler. Don't have the error message at hand now, but it was something along the lines that the typedef implicitly defined the enum zend_function_type to be int-sized, which conflicted with the : uint8_t in the actual declaration. But AFAICT it is not possible to include the uint8_t within the (effective) forward-declaration in the typedef.

It could possibly become a bit cleaner if we would define a HAVE_C23_ENUM_SIZE or similar?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that would be cleaner

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://godbolt.org/z/q9f77xe4z Just an idea, maybe something for zend_portability.h.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be the best if we end up doing more of those

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants